package com.liu.util;

/**
 * @param
 * @BelongsProject: MessageQueueDEMO
 * @BelongsPackage: com.liu.util
 * @author: L
 * @Date: 2023/10/13 10:08
 * @return
 */

public class HashFixedLength {
    // 生成4位的byte数组
    public static byte[] encode(String str) {
        int hashCode = str.hashCode();
        return intToByteArray(hashCode);
    }

    private static byte[] intToByteArray(int a) {
        return new byte[]{
                (byte) ((a >> 24) & 0xFF),
                (byte) ((a >> 16) & 0xFF),
                (byte) ((a >> 8) & 0xFF),
                (byte) (a & 0xFF)
        };
    }
}

